<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>鼠标移入提示框2.li</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        ul {
            list-style: none;
            padding: 20px;
            background-color: aquamarine;
            margin: 100px;

        }

        ul>li {
            margin: 5px;
            background-color: aqua;
            font: 18px/30px '';
        }

        div {
            width: 200px;
            height: 50px;
            color: bisque;
            font: 18px/50px '';
            background-color: rgb(246, 106, 246);
            text-align: center;
            border-radius: 10px;
            position: absolute;
            top: 0;
            left: 0;
            display: none;

        }

        div>p {
            width: 0;
            height: 0;
            border: 10px solid transparent;
            border-top: 10px solid rgb(191, 4, 191);
            position: absolute;
            left: 100px;
            top: 50px;
        }
    </style>
</head>

<body>
    <ul>
        <li>0001</li>
        <li>0002</li>
        <li>0003</li>
        <li>0004</li>
        <li>0005</li>
    </ul>
    <div>
        提示框
        <p></p>
    </div>

</body>

</html>
<script>
    var liObj = document.querySelectorAll('li')
    var divObj = document.querySelector('div')
    // console.log(liObj);onmousemove
    liObj.forEach(function (item) {
        item.onmousemove = function (e) {
            var e = e || window.event
            
            var left = e.pageX
            var top = e.pageY - (parseInt(getComputedStyle(divObj).height)) - 10
            // console.log(this);
            if (this) {
                divObj.style.display = 'block'
                divObj.style.left = left + 'px'
                divObj.style.top = top + 'px'
            } 
            
        }
        item.onmouseleave=function(){
            divObj.style.display = 'none'
        }
    })


</script>